<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
     <meta http-equiv="pragma" content="no-cache"/>
	 <meta http-equiv="cache-control" content="no-cache"/>
	 <meta http-equiv="expires" content="0"/>   
     <%@ include file="../include/common.jsp"%>
     <%@ include file="../include/tree.jsp"%>
    <link href="${pageContext.request.contextPath}/style/default/form/ui.tabs.css" type="text/css" rel="stylesheet" media="print, projection, screen"/>
     <style type="text/css">
		.ztree {margin-top: 5px;border: 1px solid #617775;background: #fff;width:220px;height:350px;overflow-y:scroll;overflow-x:auto;}
	 </style>
	 <script type="text/javascript">
	 	function showMenu() {
			var cityObj = $("#resTypeName");
			var cityOffset = $("#resTypeName").offset();
			$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
			$("body").bind("mousedown", onBodyDown);
		}
		function hideMenu() {
			$("#menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "resTypeId" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)&&$('#resTypeName').val()!='') {
				hideMenu();
			}
		}
		function onClick(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("resTypeTree"),
			nodes = zTree.getSelectedNodes(),
			v = "";
			if(nodes.length!=1 ){
				return;
			}
			if( nodes[0].isParent){
				zTree.expandNode(nodes[0]);
				return;
			}
			var resTypeId = nodes[0].id;
			selfFound = nodes[0].selfFound;
			hideMenu();
			
			$("#resTypeId").attr("value", resTypeId);
			$("#resTypeName").attr("value", nodes[0].name);
			$("#resTypeName").blur();
			
			
		}
		var setting = {
			async: {
				enable: true,
				url:"res-type!typeTree.action",
				dataType: "text",
				autoParam:["id"]
			},
			callback: {
				onClick: onClick
			},
			view: {
				dblClickExpand: false,
				showLine: false
			}
		};
		
		//导出
		function exportTemplate(){
			var resTypeName = $('#resTypeName');
			if(resTypeName.val()!=''){
				var resTypeId= $('#resTypeId').val();
				window.location="res-type!excuteExport.action?id="+resTypeId;
			}else{
				resTypeName.focus();
			}
		}
		
		$(document).ready(function(){
			 $.fn.zTree.init($("#resTypeTree"),setting);
			 
			 var excuteInfo = "${info}";
			 if(excuteInfo!=''){
			 	getTopWin(window).getMessageBox().tip(excuteInfo,{timeout:1500});
			 }
		});	
		
		function sub(){
			var upload= $('#upload');
			if(upload.val()==''){
				upload.focus();
				return false;
			}
			var path = upload.val().substring(upload.val().indexOf('.'));
			if(path=='.xls'||path=='.xlsx'){
				var resId='${resId}';
				if(resId==''&&$('#isRoot').attr('checked')!="checked"){
					getTopWin(window).getMessageBox().alert("当前无父资源,必须设置为顶级资源","提示");
					return false;
				}else{
					return true;
				}
				
			}else{
				getTopWin(window).getMessageBox().alert("只能上传以.xls或者.xlsx为后缀名的Excel文本","提示");
				return false;
			}
		}
	 </script>
  </head>
  
  <body >
    	<ul class="ui-tabs-nav">
			<li ><a href="../resource/res!guide.action?id=${resId}&viewId=${viewId}" target="_self" style="text-decoration:none;"><span>新增单个资源</span></a></li> 
			<li><a href="../integration/tivoli!guide.action?id=${resId}&viewId=${viewId}" target="_self" style="text-decoration:none;"><span>集成TIVOLI资源</span></a></li>
			<li ><a href="../integration/inmp!guide.action?id=${resId}&viewId=${viewId}" style="text-decoration:none;"><span>集成朗易资源</span></a></li>
			<li ><a href="../integration/inmpop!guide.action?id=${resId}&viewId=${viewId}" style="text-decoration:none;"><span>集成ZOHO资源</span></a></li>
			<li class="ui-tabs-selected"><a href="#" style="text-decoration:none;"><span>导入资源</span></a></li> 
		</ul>
	<div class="ui-tabs-panel"/>
  <form id="uploadForm" name="uploadForm" action="${pageContext.request.contextPath}/resource/res-type!excuteImport.action?resId=${resId}&viewId=${viewId}" enctype="multipart/form-data" method="post" onsubmit="return sub()">
     <table class="table_eidt" id="restable">
     	<tbody>
     		<tr>
     			<td class="td_left" style="width: 150px">
     				<span class="span_alert">*</span>资源类型
     			</td>
     			<td class="td_right" style="width:370px;">
     				<input type="text" name="resTypeName" id="resTypeName" style="width:223px;"  class="input_text tree_res" onfocus="showMenu(); return false;" readonly="readonly"/>
					<span id="resTypeNameTip"></span>
					<input type="hidden" name="resTypeId" id="resTypeId"  />
     			</td>
     			<td class="td_left" style="width: 150px">下载模板</td>
     			<td class="td_right">
     				<button type="button" id ="export" value="导出" class="btn-4" onclick="exportTemplate()" >导出</button>
     			</td>
     		</tr>
     		<tr>
     			<td class="td_left">导入资源</td>
     			<td class="td_right" colspan="3">
     				<input type='checkbox' value="1" name="isRoot" id="isRoot"  />设为顶级资源
     				<input name="upload" id="upload" type="file" value="浏览"  style="width:430px; height:22px;"  />
     				<button type="submit"  id ="import" value="导入" class="btn-4" >导入</button>
     			</td>
     		</tr>
     	</tbody>
     </table>
     
      <div id="menuContent" class="menuContent" style="display:none; position: absolute;">
	  	<ul id="resTypeTree" class="ztree" style="margin-top:0;padding-left:0;  width:220px; height:350px; "></ul>
   	  </div>
  </form>
  </body>
</html>
